	var getContentsUrlCall = null;			// Need to set
	var MAX_PAGES_OPTIONS = null;			// Need to set
	var CONTENTS_SHOWN_PER_PAGE = null;		// Need to set
	var MAX_CONTENT_HEIGTH = null;			// Need to set
	var allContentsLoaded = null;			// Need to set
	var contents = null;					// Need to set
	var numberPages = null;					// Need to set
	var user_id = null;						// Need to set
	var getNotAnonymous = null;				// Need to set
	var lastIdContent =null;				// Need to set
	var currentPage = 1;

	var turningPage = false;
	var deletingContent = false;


	function nextPage() {
		if (turningPage == true)
			return;		

		// Have already loaded that page
		if (Math.ceil(contents.length/CONTENTS_SHOWN_PER_PAGE) > currentPage ) {
			currentPage++;
			
			showPageContent();
			showPageButtons();
		} else {
			if (allContentsLoaded)
				return;
			
			turningPage = true;
			
			spinner.spin(spinnerTarget);
			
			$.post(getContentsUrlCall + "&limit=" + CONTENTS_SHOWN_PER_PAGE + "&from_id=" + lastIdContent + "&get_not_anonymous=" + getNotAnonymous, {
			}, function(response){
				var newContent = JSON.parse(response);
				allContentsLoaded = (newContent.length < CONTENTS_SHOWN_PER_PAGE) ? true : false;
				
				contents = contents.concat( newContent );
				lastIdContent = contents[ contents.length - 1 ].content_id;
				
				currentPage++;
				
				showPageContent();
				turningPage = false;					
				showPageButtons();
				spinner.stop();
			});
		}
		
	}

	function prevPage() {
		if (currentPage > 1) {
			currentPage--;
			
			showPageContent();
			showPageButtons();
		}
	}

	function goToPage(number) {
		if (turningPage == true)
			return;

		// Have already loaded that page
		if (Math.ceil(contents.length/CONTENTS_SHOWN_PER_PAGE) >= number ) {
			currentPage = number;
			
			showPageContent();
			showPageButtons();
		} else {
			if (allContentsLoaded)
				return;
			
			spinner.spin(spinnerTarget);
			
			turningPage = true;
			
			var amountToLoad = (number - Math.ceil(contents.length/CONTENTS_SHOWN_PER_PAGE))*CONTENTS_SHOWN_PER_PAGE;
			
			$.post(getContentsUrlCall + "&limit=" + amountToLoad + "&from_id=" + lastIdContent + "&get_not_anonymous=" + getNotAnonymous, {
			}, function(response){
				var newContent = JSON.parse(response);
				allContentsLoaded = (newContent.length < CONTENTS_SHOWN_PER_PAGE) ? true : false;
				
				contents = contents.concat( newContent );
				lastIdContent = contents[ contents.length - 1 ].content_id;
				
				currentPage = number;
				
				showPageContent();
				turningPage = false;
				showPageButtons();
				spinner.stop();
			});
		}
	}

	function showPageContent() {
		var to = (currentPage*CONTENTS_SHOWN_PER_PAGE < contents.length) ? currentPage*CONTENTS_SHOWN_PER_PAGE : contents.length;
		
		for (var i = (currentPage - 1)*CONTENTS_SHOWN_PER_PAGE; i < to; i++) {
			showContentAt(i - (currentPage - 1)*CONTENTS_SHOWN_PER_PAGE, contents[i]);
		}
		
		for (var i = to; i < currentPage*CONTENTS_SHOWN_PER_PAGE; i++) {
			var index = i - (currentPage - 1)*CONTENTS_SHOWN_PER_PAGE;
			
			document.getElementById('content-div-' + index).style.display = 'none';
			document.getElementById('hr-' + index).style.display = 'none';
		}
	}

	function showPageButtons() {
		var pagesInnerHTML = '';
		
		if (MAX_PAGES_OPTIONS >= numberPages) {
			for (var i = 1; i <= numberPages; i++) {
				if (i == currentPage)
					pagesInnerHTML += '<a id="page-link-' + i + '" class="pages-link-number-selected" href="#" onclick="goToPage(' + i + ')" >';
				else
					pagesInnerHTML += '<a id="page-link-' + i + '" class="pages-link-number" href="#" onclick="goToPage(' + i + ')" >';
					
				pagesInnerHTML += i;
					
				pagesInnerHTML += '</a>';
			}
		} else {
			var pagesEachSide = Math.floor(MAX_PAGES_OPTIONS/2);
			
			if (currentPage + pagesEachSide <= numberPages) {
				var startingPage = (pagesEachSide >= currentPage) ? 1 : currentPage - pagesEachSide;
				var endPage =  startingPage + MAX_PAGES_OPTIONS;
			} else {
				var startingPage = numberPages - MAX_PAGES_OPTIONS + 1;
				var endPage =  numberPages + 1;
			}
			
			for (var i = startingPage; i < endPage; i++) {
				if (i == currentPage)
					pagesInnerHTML += '<a id="page-link-' + i + '" class="pages-link-number-selected" href="#" onclick="goToPage(' + i + ')" >';
				else
					pagesInnerHTML += '<a id="page-link-' + i + '" class="pages-link-number" href="#" onclick="goToPage(' + i + ')" >';
					
				pagesInnerHTML += i;
					
				pagesInnerHTML += '</a>';
			}
		}
		
		if (document.getElementById('pages') != null)
			document.getElementById('pages').innerHTML = pagesInnerHTML;
	}
